package com.gblw.rjkf.pj.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gblw.rjkf.pj.entity.SysPermissions;
import com.gblw.rjkf.pj.service.SysPermissionsService;
import com.gblw.rjkf.pj.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * SysPermissionsController(SysPermissions)
 *
 * @author wj
 * @since 2024-09-20 19:47:08
 */
@Api(tags = {"SysPermissions"})
@RestController
@RequestMapping("sys/sysPermissions")
public class SysPermissionsController {

    /**
     * 服务对象
     */
    @Resource
    private
    SysPermissionsService sysPermissionsService;

    /**
     * 分页查询所有数据
     *
     * @return 所有数据
     */
    @SaCheckPermission(value = "sys:permissions:list")
    @ApiOperation("分页查询所有数据")
    @GetMapping("/list")
    public Result selectAll() {
        return sysPermissionsService.buildMenuTree();
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @SaCheckPermission(value = "sys:permissions:list")
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("getById/{id}")
    public Result selectOne(@PathVariable Serializable id) {
        return Result.success("查询成功", sysPermissionsService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param sysPermissions 实体对象
     * @return 新增结果
     */
    @SaCheckPermission(value = "sys:permissions:insert")
    @ApiOperation("新增数据")
    @PostMapping("/insert")
    public Result insert(@RequestBody SysPermissions sysPermissions) {
        return sysPermissionsService.insert(sysPermissions);
    }

    /**
     * 修改数据
     *
     * @param sysPermissions 实体对象
     * @return 修改结果
     */
    @SaCheckPermission(value = "sys:permissions:update")
    @ApiOperation("修改数据")
    @PostMapping("/update")
    public Result update(@RequestBody SysPermissions sysPermissions) {
        return sysPermissionsService.update(sysPermissions);
    }

    /**
     * 批量删除数据
     *
     * @param idList 主键集合
     * @return 删除结果
     */
    @SaCheckPermission(value = "sys:permissions:delete")
    @ApiOperation("批量删除数据")
    @PostMapping("/delete")
    public Result delete(@RequestParam("idList") List<Serializable> idList) {
        int result = 0;
        if (idList != null && idList.size() > 0) {
            sysPermissionsService.removeByIds(idList);
        }
        ;
        return Result.success("删除成功", "");
    }

    /**
     * 批量删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @SaCheckPermission(value = "sys:permissions:delete")
    @ApiOperation("单个删除数据")
    @PostMapping("/deleteIds/{id}")
    public Result delete(@PathVariable Serializable id) {
        sysPermissionsService.removeById(id);
        return Result.success("删除成功", "");
    }


}
